from flask import Flask, render_template, request
import sqlite3
import datetime

app = Flask(__name__)

@app.route('/')
def index():
    if request.method == "GET":
        return render_template("index.html", daLi= daLi(), xizang = xizang(), zjj = zjj(), cs = cs())

@app.route('/index.html')
def home():
    # return render_template('index.html')
    return index()

# 柱状图
@app.route('/bar.html')
def bar():
    if request.method == "GET":
        return  render_template("bar.html", daLi = daLi(), xizang = xizang(), zjj = zjj(),cs= cs())

# 饼图
@app.route('/pie.html')
def pie():
    if request.method == "GET":
        return  render_template("pie.html", daLi = daLi(), xizang = xizang(), zjj = zjj(),cs= cs())
# 折线图
@app.route('/line.html')
def line():
  if request.method == 'GET':
      return render_template("line.html", daLi = daLi(), xizang=xizang(), zjj=zjj(),cs=cs())

# 气泡图
@app.route('/bubble.html')
def bubble():
    if request.method == "GET":
        return render_template("bubble.html", daLi=daLi(), xizang=xizang(), zjj=zjj(), cs=cs())

# 散点图
@app.route('/scatter.html')
def scatter():
    con = sqlite3.connect("dbname.db")
    cur = con.cursor()
    sql = "select 价格 price, 景区 area, 销量 sale from  西藏 group by sale"
    data = cur.execute(sql)
    dataX = []
    dataY = []
    dataS = []
    for item in data:
        dataY.append(item[0])
        dataX.append(item[1])
        dataS.append(item[2])
    cur.close()
    con.close()
    return render_template('scatter.html', dataX=dataX, dataY=dataY, dataS=dataS)

# 极坐标下的堆积柱状图
@app.route('/polar-bar.html')
def polar():
    if request.method == "GET":
        return render_template("polar-bar.html", daLi=daLi(), xizang=xizang(), zjj=zjj(), cs=cs())

# 测试图
@app.route('/test.html')
def test():
    if request.method == "GET":
        return render_template("test.html", daLi=daLi(), xizang=xizang(), zjj=zjj(), cs=cs())

# 大理数据
def daLi():
    con = sqlite3.connect("dbname.db")
    cur = con.cursor()
    sql = "select * from  大理"
    data = cur.execute(sql)
    # 将data数据集放入列表中
    datalist = []
    for item in data:
        datalist.append(item)
    cur.close()
    con.close()
    return datalist

# 张家界数据
def zjj():
    con = sqlite3.connect("dbname.db")
    cur = con.cursor()
    sql = "select * from  张家界"
    data = cur.execute(sql)
    # 将data数据集放入列表中
    datalist = []
    for item in data:
        datalist.append(item)
    cur.close()
    con.close()
    return datalist

# 西藏数据
def xizang():
    con = sqlite3.connect("dbname.db")
    cur = con.cursor()
    sql = "select * from  西藏"
    data = cur.execute(sql)
    # 将data数据集放入列表中
    datalist = []
    for item in data:
        datalist.append(item)
    cur.close()
    con.close()
    return datalist

# 长沙数据
def cs():
    con = sqlite3.connect("dbname.db")
    cur = con.cursor()
    sql = "select * from  长沙"
    data = cur.execute(sql)
    # 将data数据集放入列表中
    datalist = []
    for item in data:
        datalist.append(item)
    cur.close()
    con.close()
    return datalist

if __name__ == '__main__':
    app.run()


